/*
 * Copyright 2011 Philippe Blanc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package me.l1k3.fx.client;

import me.l1k3.core.client.Core;
import me.l1k3.fx.client.channel.StyleChannel;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Style.Unit;

public class FXPosition extends FXChannel {

	//- - - factory
	
    public static FXPosition to(Element element, int x, int y) {
        FXPosition position = new FXPosition();
        position.setX(element, x);
        position.setY(element, y);
        position.init(element);
        
        return position;
    }
    
    public static FXPosition to(Element element, int startX, int startY, int endX, int endY) {
        FXPosition position = new FXPosition();
        position.setX(startX, endX);
        position.setY(startY, endY);
        position.init(element);
        
        return position;
    }
	
	//- - -
	
    public void to(int x, int y) {
        Element element = getContext().getElement();
        setX(element, x);
        setY(element, y);
    }
    
    public void to(int startX, int startY, int endX, int endY) {
        setX(startX, endX);
        setY(startY, endY);
    }
    
    //- - -
    
    public void setX(Element element, int end) {
        setX(Core.parseInt(element.getStyle().getLeft()), end);
	}
	
    public void setX(int start, int end) {
		add(StyleChannel.setStyle(getType(), "left", start, end, Unit.PX));
	}
	
    public void setY(Element element, int end) {
        setY(Core.parseInt(element.getStyle().getTop()), end);
	}
	
    public void setY(int start, int end) {
	    add(StyleChannel.setStyle(getType(), "top", start, end, Unit.PX));
	}
}
